home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / SATcollision][ ƒ / sApple][.p < prev    next >
Encoding:
Text File  |  1993-09-21  |  2.1 KB  |  98 lines  |  [TEXT/PJMM]

  1. { Apple sprite for SATcollision][ }
  2. { No, it has nothing to do with old Apple computers :-) }
  3.  
  4. unit sApple;
  5.  
  6. interface
  7.  
  8.     uses
  9.         SAT;
  10.  
  11.     var
  12.         nammSound, bliaehSound: Handle;
  13.         goodFace, badFace: FacePtr;
  14.         coreDump: FacePtr;
  15.  
  16.     procedure InitApple;
  17.     procedure SetupApple (me: SpritePtr);
  18.     procedure HandleApple (me: SpritePtr);
  19.     procedure HitApple (me, him: SpritePtr);
  20.  
  21. implementation
  22.  
  23.     procedure InitApple;
  24.         var
  25.             i: integer;
  26.     begin
  27.         nammSound := SATGetNamedSound('namm');
  28.         bliaehSound := SATGetNamedSound('bliaeh');
  29.         goodFace := GetFace(132);
  30.         badFace := GetFace(133);
  31.         coreDump := GetFace(135);
  32.     end;
  33.  
  34.     procedure SetupApple (me: SpritePtr);
  35.     begin
  36.         me^.speed.h := 1 + Rand(3);
  37.         me^.kind := -2; {Enemy kind}
  38.         me^.face := GoodFace;
  39.         SetRect(me^.hotRect, 0, 0, 32, 32);
  40.     end;
  41.  
  42. {We use kind -2 for fresh apples and kind -3 for bad apples. We avoid -1, since it doesn't count for the "anymonsters" flag.}
  43. {Note that the "kind" field is not modified my SAT since we are not using KindCollision!}
  44.  
  45.     procedure HandleApple (me: SpritePtr);
  46.     begin
  47.  
  48.         case me^.kind of
  49.             -2: 
  50.                 me^.face := goodFace;
  51.             -3: 
  52.                 me^.face := badFace;
  53.         end;
  54.  
  55.         me^.position.h := me^.position.h + me^.speed.h;
  56.         if me^.position.h > offSizeH - 16 then
  57.             begin
  58.                 me^.speed.h := -1 - Rand(3);
  59.                 if Rand(2) = 0 then
  60.                     me^.kind := -3
  61.                 else
  62.                     me^.kind := -2;
  63.             end;
  64.         if me^.position.h < -16 then
  65.             begin
  66.                 me^.speed.h := 1 + Rand(3);
  67.                 if Rand(2) = 0 then
  68.                     me^.kind := -3
  69.                 else
  70.                     me^.kind := -2;
  71.             end;
  72.     end;
  73.  
  74.     procedure HitApple;
  75.     begin
  76.         if him^.task = @HandleApple then
  77.             me^.kind := -3 {Colliding apples corrupt each other!}
  78.         else
  79. {If "him" is not an apple, then it must be the player!}
  80.             if him^.mode >= 0 then {if the player feels bad, don't eat}
  81.                 case me^.kind of
  82.                     -2: 
  83.                         begin
  84.                             SATSoundPlay(nammSound, 1, false);
  85.                             me^.task := nil;
  86.                             him^.mode := 25;
  87.                             SATPlotFace(coreDump, nil, nil, me^.position, true);
  88.                         end;
  89.                     -3: {Bad apple, make player feel bad.}
  90.                         begin
  91.                             him^.mode := -20;
  92.                             SATSoundPlay(bliaehSound, 2, false);
  93.                         end;
  94.                     otherwise {This shouldn't happend!}
  95.                 end;
  96.     end;
  97.  
  98. end.